﻿using FluentValidation.Internal;
using FluentValidation.Results;
using JSONDB.Model;
using JSONDB.Validation;
using JsonFlatFileDataStore;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Runtime.InteropServices;
using System.Text;
using System.Threading.Tasks;

namespace JSONDB
{
    public class JsonStore
    {
        private string path;
        private DataStore store  ;
        public JsonStore(String path) {
          this.path= path;
          this.store = new DataStore(path);
        }
       
        public async Task ConfigSaveOrUpdate(Tag item )
        {
            
            var collection = store.GetCollection<Tag>("config");
            bool isSucessful = await collection.UpdateOneAsync((Predicate<Tag>)(t => t.name.Equals(item.name)), item);    
            if(!isSucessful ) {
              await  collection.InsertOneAsync(item);
            }
          
        }

   
    }
}
